package com.polaris.live.dialog.common

import android.content.Context
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.DialogConfirmBinding

/**
 * 确认弹窗
 *
 * @author Created by lucas on 2023/10/28 09:28
 */
class ConfirmDialog(
    context: Context,
    private val content: String,
    private val confirmText: String?,
    private val cancelText: String?,
    private val onConfirmClickListener: OnClickListener,
    private val onCancelClickListener: OnClickListener?
) : CenterPopupView(context) {

    private lateinit var mBinding: DialogConfirmBinding

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_confirm
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = DialogConfirmBinding.bind(popupImplView)

        mBinding.tvContent.text = content

        if (!confirmText.isNullOrEmpty()) {
            mBinding.tvConfirm.text = confirmText
        }
        if (!cancelText.isNullOrEmpty()) {
            mBinding.tvCancel.text = cancelText
        }

        mBinding.tvConfirm.setOnSingleClickListener {
            onConfirmClickListener.onClick(it)
            dismiss()
        }
        mBinding.tvCancel.setOnSingleClickListener {
            onCancelClickListener?.onClick(it)
            dismiss()
        }
    }
}